package com.funtl.framework.web.admin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.funtl.framework.java.util.common.CommonBean;
import com.funtl.framework.java.util.exception.ServiceException;
import com.funtl.framework.java.web.orm.hibernate.dao.IHibernateDao;
import com.funtl.framework.java.web.orm.hibernate.param.HibernateParam;
import com.funtl.framework.web.admin.service.IAdminService;
import com.funtl.framework.web.entity.Admin;

@Component
public class AdminServiceImpl implements IAdminService {
	private IHibernateDao hibernateDao;
	
	@Override
	public Admin login(Admin admin) throws ServiceException {
		HibernateParam param = new HibernateParam();
		param.setPropertyTypes(new String[] {"loginId", "loginPwd"});
		param.setOperators(new String[] {"=", "="});
		param.setPropertyValues(new String[] {admin.getLoginId(), admin.getLoginPwd()});
		return hibernateDao.get(admin, param);
	}
	
	//common service

	@Override
	public Admin get(Admin entity) throws ServiceException {
		HibernateParam param = new HibernateParam();
		param.setPropertyTypes(new String[] {"id"});
		param.setOperators(new String[] {"="});
		param.setPropertyValues(new String[] {entity.getId()});
		return hibernateDao.get(entity, param);
	}

	@Override
	public List<Admin> getList(Admin entity) throws ServiceException {
		return hibernateDao.getListByEhcatch(entity, "createDate", "DESC");
	}

	@Override
	public String insert(Admin entity) throws ServiceException {
		hibernateDao.insert(entity);
		return null;
	}

	@Override
	public String delete(Admin entity) throws ServiceException {
		hibernateDao.delete(entity, "id");
		return null;
	}

	@Override
	public String update(Admin entity) throws ServiceException {
		Admin admin = get(entity);
		CommonBean.beanToBean(entity, admin);
		hibernateDao.update(entity);
		return null;
	}

	//getter setter
	
	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}

	@Resource
	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

}
